from datetime import time, datetime

import socketio

sio = socketio.Client()

my_data={}

@sio.event
def connect():
    print("已连接至服务器")


@sio.event
def disconnect():
    print("已断开服务器")


@sio.event
def my_response(data):
    global my_data
    my_data=data
    print("你的ID是：", my_data['id'])

@sio.event
def accepting_bind(data):
    global my_data
    bind_ask=input(data['msg'])
    if bind_ask=='yes':
        pass
    # 写到这里

@sio.event
def bind_status(data):
    if data["status"] is 0:
        print("连接成功")
        while True:
            message=input("请输入你要发送的信息（输入exit退出）：")
            if message.lower() == 'exit':
                break
            sio.emit('send_msg', {
                "my_id": my_data['id'],
                "msg": message,
                "stime": datetime.now()
            })
        sio.disconnect()
    else:
        pass

def main():
    url = "http://192.168.182.71:5000"
    sio.connect(url)
    bind_id = str(input("请输入你要绑定的ID："))
    sio.emit("bind_u",{
        "my_id":my_data['id'],
        "bind_id":bind_id
    })



if __name__ == '__main__':
    main()